//
//  TestFlowLayoutConstraint.m
//  MKUITestApp
//
//  Created by 苏尚进 on 2023/2/28.
//  Copyright © 2023 moon. All rights reserved.
//

#import "TestFlowLayoutConstraint.h"
#import <MKUI/MKUI.h>
#import "TestFunButton.h"
@interface TestFlowLayoutConstraint ()
@property(nonatomic,strong) MKUILayoutConstraint *flowlayout;
@end

@implementation TestFlowLayoutConstraint

+ (MKTFuncItem *)funcItem{
    return [MKTFuncItem funcWithName:@"Flow流布局约束" viewControllerClass:self];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    MKUIFlowLayoutConstraint *flowlayout = [[MKUIFlowLayoutConstraint alloc] initWithItems:@[] constraintParam:(MKUIFlowLayoutConstraintParam_V_C_C) contentInsets:UIEdgeInsetsMake(5, 10, 15, 20) interitemSpacing:10];
    flowlayout.unLimitItemSizeInBounds = YES;
    self.flowlayout = flowlayout;

    
    for(int i=0;i<5;i++){
        TestFunButton *button = [[TestFunButton alloc] initWithTitle:[NSString stringWithFormat:@"测试%@",@(i)]];
        [self.view addSubview:button];
        [self.flowlayout addItem:button];
    }
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:(UIBarButtonSystemItemRefresh) target:self action:@selector(_onRefresh)];
}
- (void)_onRefresh{
    [self.view setNeedsLayout];
}
- (void)viewWillLayoutSubviews{
    [super viewWillLayoutSubviews];
    CGRect bounds = self.safeBounds;
    CGRect f1 = bounds;
    f1.size = [self.flowlayout sizeThatFits:bounds.size resizeItems:YES];
    self.flowlayout.bounds = f1;
    [self.flowlayout layoutItemsWithResizeItems:YES];
}

@end
